package parser;

import antlr.RecognitionException;
import java.util.*;

class ForStmt extends LoopStmt {

    Expr var;
    Expr collect;
    Expr temp;

    ForStmt(Expr var, Expr collect, Expr temp) throws RecognitionException {
        this.var = var;
        var.lhs();
        this.collect = collect;
        this.temp = temp;
        temp.lhs();
    }

    void write(ByteStream out) throws RecognitionException {
        out.line(line);
        collect.write(out);
        out.write(Opcodes.ITER);
        int target = out.here();
        for (Patch c : continues) {
           out.patch(c);
        }
        Patch patch = out.branch(Opcodes.NEXT);
        var.writeLHS(out);
        suite.write(out);
        out.branch_back(Opcodes.END_LOOP, target);
        patch.patch(out);
        for (Patch b : breaks) {
           out.patch(b);
        }
    }

}

